package com.bifrost.repository;

import com.bifrost.entity.ProductSku;
import com.bifrost.entity.SkuOptionValue;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author rangf
 * @date 2018/3/26
 */
public interface SkuOptionValueRepository  extends JpaRepository<SkuOptionValue, Long> {
    List<SkuOptionValue> findAllByProductSku(ProductSku productSku);

    @Query(value = "DELETE FROM SKU_OPTION_VALUE WHERE SKU_ID = ?1 AND SKU_OPTION_VALUE_XREF_ID NOT IN (?2)" ,nativeQuery = true)
    @Modifying
    void deleteNotExistOption(Long skuId , List<Long> notNullOption);
}
